<template>
  <div class="add-project">
    <el-button type="primary" @click="dialogVisible = true" size="small" style="margin-top: 6px;float: right;"><i class="el-icon-plus"></i>新建项目</el-button>
    <div>
      <el-dialog title="新增项目" :visible.sync="dialogVisible" width="35%" :before-close="handleClose">
        <el-form ref="form" :model="projectForm" label-width="80px">
          <el-form-item label="项目名">
            <el-input placeholder="请输入项目名" v-model="projectForm.name"></el-input>
          </el-form-item>
          <el-form-item label="版本号">
            <el-input placeholder="请输入版本号" v-model="projectForm.version"></el-input>
          </el-form-item>
          <el-form-item label="项目类型">
            <el-select placeholder="请选择项目类型" v-model="projectForm.type">
              <el-option label="App" value="1"></el-option>
              <el-option label="Web" value="2"></el-option>
              <el-option label="PC" value="3"></el-option>
              <el-option label="H5" value="4"></el-option>
              <el-option label="其他" value="0"></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="项目描述">
            <el-input type="textarea" :rows="3" placeholder="请输入内容" v-model="projectForm.description">
            </el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取 消</el-button>
          <el-button type="primary" @click="addProjects(projectForm)">确 定</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>

<script>
import { addProject } from '@/api/project'
export default {
  data () {
    return {
      dialogVisible: false,

      projectForm: {
        name: '',
        type: '1',
        description: '',
        createTime: '',
        updateTime: '',


      }
    }
  },

  methods: {
    handleClose (done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => { });
    },

    addProjects (data) {
      this.projectForm = {}

      this.projectForm.createTime = new Date()
      this.projectForm.updateTime = new Date()
      addProject(data).then(resq => {
        debugger
        if (resq.code == 200) {
          this.dialogVisible = false

          this.$message({
            message: resq.message,
            type: 'success'
          });
          this.$emit("getProject");

        } else {
          this.$message.error('添加失败！');
          console.log(resq)
        }

      })

    }
  },

  mounted () {
  }

}
</script>

<style scoped>
.add-project >>> .el-select {
  display: contents;
}
</style>